package com.zxy.leetcode._00500_00599._00500_00509;

/**
 * 斐波那契数
 */
public class Test00509 {

    public static void main(String[] args) {
        Test00509 test = new Test00509();
        System.out.println(test.fib(1));
        System.out.println(test.fib(2));
        System.out.println(test.fib(4));
    }

    public int fib(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }

        int a = 0;
        int b = 1;
        int c = a + b;
        for (int i=2; i<=n; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return c;
    }
}
